Skip to content

feat(function): implemented context.fail() functionality #112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

alitariksahin
Copy link
Contributor

A special header + status combination makes a request with retries fail immediately.
header: "Upstash-NonRetryable-Error": "true"
status: 489

context.fail() is made publicly available

@alitariksahin alitariksahin self-assigned this Jun 17, 2025
Copy link

linear bot commented Jun 17, 2025

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements the new context.fail() functionality to allow workflows to fail immediately via a special header and status code.

  • Introduces a new "workflow-failed" state in the workflow processing flow.
  • Updates test suites and types, along with error handling and API response construction, to support the fail behavior.
  • Modifies serve options and endpoint response logic to return status 489 with the "Upstash-NonRetryable-Error" header when a workflow fails.

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/workflow-requests.ts Adds a branch to handle WorkflowAbort with failWorkflow flag.
src/workflow-requests.test.ts Adds tests for context.fail() behavior validating the new workflow state.
src/types.ts Extends FinishCondition to include "workflow-failed".
src/serve/serve.test.ts Tests qstash failure response integration for context.fail.
src/serve/options.ts Processes "workflow-failed" condition to send a Response with status 489.
src/serve/index.ts Integrates handling of "workflow-failed" into the serve workflow.
src/serve/authorization.ts Overrides fail() in DisabledWorkflowContext to do nothing.
src/error.ts Updates WorkflowAbort to accept and assign failWorkflow flag.
src/context/context.ts Adds context.fail() which throws WorkflowAbort with failWorkflow true.
src/context/context.test.ts Adds tests to assert that context.fail() properly throws the expected error.

@@ -158,6 +159,8 @@ export const triggerRouteFunction = async ({
return ok("workflow-was-finished");
} else if (!(error_ instanceof WorkflowAbort)) {
return err(error_);
} else if (error_.failWorkflow) {
Copy link
Preview

Copilot AI Jun 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider restructuring the error handling logic by nesting the WorkflowAbort conditions together (i.e. checking failWorkflow and cancelWorkflow inside an explicit WorkflowAbort branch) to improve clarity.

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant